package arithmetic;

import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * 给出一个字符串数组，转换成摩斯密码，然后判断有多少种不同的组合
 *
 * @author gaojie
 * @date 2022-04-10
 */
public class MorsePassword {

    @Test
    void test() {

        String[] words = {"gin", "zen", "gig", "msg"};
        assert fun(words) == 2;

        words = new String[]{"a"};
        assert fun(words) == 1;

    }

    int fun(String[] words) {
        String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        Set<String> morseStrSet = new HashSet<>();
        for (String word : words) {
            StringBuilder sb = new StringBuilder();
            for (char c : word.toCharArray()) {
                sb.append(morse[c - 97]);
            }
            morseStrSet.add(sb.toString());
        }
        return morseStrSet.size();
    }
}
